package com.maxmlr.framework.mybatisplus.mapper;

import com.maxmlr.framework.mybatisplus.session.DefaultSqlSession;
import lombok.AllArgsConstructor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName MapperProxy
 * @Description TODO
 * @Author maxiao
 * @Date 2020/3/23 下午3:07
 * @Version V1.0
 */
@AllArgsConstructor
public class MapperProxy<T> implements InvocationHandler {

    private final DefaultSqlSession sqlSession;
    private final Class<T> mappperInterface;


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getDeclaringClass().getName() + "." + method.getName();
        MapperRegistory mapperRegistory = sqlSession.getConfiguration().getMapperRegistory();
        if (mapperRegistory.containsKey(methodName)) {
            MapperData mapperData = mapperRegistory.get(methodName);
            switch (mapperData.getExecutorType()) {
                case DELETE:
                    break;
                case INSTER:
                    break;
                case SELECT:
                    return sqlSession.selectList(mapperData, String.valueOf(args[0]));
                case UPDATE:
                    break;
                default:
            }

        }
        return method.invoke(proxy, args);
    }
}
